<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            width: 500px;
            height: 400px;
            position: relative;

        }

        .container div {
            width: 400px;
            height: 300px;
            background-color: #eee;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
    <script>
        // function handleTabs() {
        //     var btns = document.querySelectorAll('button')
        //     var divs = document.querySelectorAll('.container div')
        //     for (let i = 0; i < btns.length; i++) {
        //         btns[i].onclick = function () {
        //             for (var j = 0; j < btns.length; j++) {
        //                 divs[j].style.display = 'none';
        //             }
        //             divs[i].style.display = 'block';
        //         }
        //     }
        // }
        function MyTab() {
            var btns = document.querySelectorAll('button')
            var divs = document.querySelectorAll('.container div')
            for (let i = 0; i < btns.length; i++) {
                btns[i].onclick = function () {
                    for (var j = 0; j < btns.length; j++) {
                        divs[j].style.display = 'none';
                    }
                    divs[i].style.display = 'block';
                }
            }
        }
        window.onload = function () {
            var tab = new MyTab()
        }
    </script>
</head>

<body>
    <div>
        <button>按钮1</button>
        <button>按钮2</button>
        <button>按钮3</button>
        <div class="container">
            <div style="display:block">内容1</div>
            <div>内容2</div>
            <div>内容3</div>

        </div>
    </div>

</body>

</html>